#include "../Server.hpp"

int main()
{
    Sock sock;
    int sockfd=sock.Fd();
    if(!sock.CreateServer(8080))
    {
        ERR_LOG("server create failed!!");
    }
    int newfd=sock.Accept();
    Sock new_sock(newfd);
    while(true)
    {
        char buffer[1024];
        memset(buffer,0,sizeof(buffer));
        ssize_t s=new_sock.Recv(buffer,sizeof(buffer)-1);
        if(s>0)
        {
            buffer[s]='\0';
            std::string str="client# ";
            str+=buffer;
            new_sock.Send((char*)str.c_str(),str.size());
        }
        else if(s==0)
        {
            DBG_LOG("aside close,sock:%d",newfd);
            new_sock.Close();
        }
        else
        {
            ERR_LOG("server recv failed");
            new_sock.Close();
        }
    }

    return 0;
}